package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.design.Button;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IButtonDao;
import cn.edu.sjtu.se.dslab.project.BusZone;


@Repository("buttonDao")
public class ButtonDaoImpl implements IButtonDao {

	@Resource(name = "baseDao")
	private IBaseDao<Button> baseDao;
	
	@Override
	public Button queryById(long id) {
		return baseDao.queryById(Button.class, id);
	}

	@Override
	public Button queryByName(String name) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Button where name=");
		hql.append("'" + name + "'");
		return baseDao.queryObject(hql.toString());
	}

	@Override
	public Button queryByCode(String code, long projectId) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Button where code=");
		hql.append("'" + code + "' and project_id = '" + projectId + "'");
		return baseDao.queryObject(hql.toString());
	}

	@Override
	public List<Button> queryByList() {
		return baseDao.queryList(Button.class.getName());
	}

	@Override
	public void save(Button button) {
		baseDao.save(button);
	}

	@Override
	public Button update(Button button) {
		return baseDao.update(button);
	}

	@Override
	public void deleteButton(Button button) {
		baseDao.delete(button);
	}

	@Override
	public List<Button> queryByProject(long projectId) {
		StringBuilder sql = new StringBuilder();
		sql.append("from Button where project_id='");
		sql.append(projectId).append("'");
		return baseDao.query(sql.toString());
	}

	@Override
	public Button queryByProjectAndName(long projectId, String name) {
		StringBuilder sql = new StringBuilder();
		sql.append("from Button where project_id='");
		sql.append(projectId).append("' and name = '").append(name).append("'");
		return baseDao.queryObject(sql.toString());
	}

}
